﻿package mortal.game.view.mainUI.avatar
{
    import Message.Public.*;
    import com.gengine.global.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.view.common.*;
    import mortal.game.view.mainUI.roleAvatar.*;

    public class BossAvatar extends EntityAvatar
    {
        protected var _mofaBar:BaseProgressBar;
        protected var _bossInfo:BossInfo;

        public function BossAvatar()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            addChild(_avatar);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._mofaBar.dispose(param1);
            this._mofaBar = null;
            this._bossInfo = null;
            super.disposeImpl(param1);
            return;
        }// end function

        override protected function addBg() : void
        {
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.AvatarBossBg, 0, 0, this));
            return;
        }// end function

        override protected function addAvatar() : void
        {
            _avatar = UIFactory.gImageBitmap("", 5, 5, this);
            return;
        }// end function

        override protected function addLifeBar() : void
        {
            _shengmingBar = new BaseProgressBar();
            _shengmingBar.setProgress(ImagesConst.AvatarBossLife, false, 2, 0, 283, 16);
            _shengmingBar.setTweenProgress(ImagesConst.AvatarBossLife, false, 2, 0, 283, 16);
            _shengmingBar.setBg(BitmapDataConst.AlphaBMD, true, 283, 18);
            _shengmingBar.isCacheBmp = true;
            if (Global.isDebugModle)
            {
                _shengmingBar.setLabel(BaseProgressBar.ProgressBarTextOver, 44, -3);
            }
            else
            {
                _shengmingBar.setLabel(BaseProgressBar.ProgressBarTextPercent, 40, -2);
            }
            _shengmingBar.x = 70;
            _shengmingBar.y = 31;
            this.addChild(_shengmingBar);
            return;
        }// end function

        override protected function addName() : void
        {
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 12;
            _name = UIFactory.gTextField("", 84, 8, 100, 20, this, _loc_1, false);
            return;
        }// end function

        override protected function addLevel() : void
        {
            var _loc_1:* = GlobalStyle.textFormatBai.center();
            _loc_1.size = 12;
            _level = UIFactory.gTextField("", 38, 48, 50, 20, this, _loc_1, false);
            return;
        }// end function

        protected function addMana() : void
        {
            this._mofaBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._mofaBar.createDisposedChildren();
            this._mofaBar.setProgress(ImagesConst.AvatarBossLifeMana, false, 3, 1, 283, 18);
            this._mofaBar.setBg(BitmapDataConst.AlphaBMD, true, 283, 18);
            this._mofaBar.setLabel(BaseProgressBar.ProgressBarTextOver, 20, -3);
            this._mofaBar.x = 73;
            this._mofaBar.y = 45;
            this.addChild(this._mofaBar);
            return;
        }// end function

        override protected function addBuff() : void
        {
            _buffPanel = UICompomentPool.getUICompoment(BuffPanel);
            _buffPanel.createDisposedChildren();
            _buffPanel.x = 79;
            _buffPanel.y = 50;
            this.addChild(_buffPanel);
            return;
        }// end function

        override public function updateLevel(event:Event = null) : void
        {
            if (!_entityInfo)
            {
                return;
            }
            _level.text = _entityInfo.entityInfo.level.toString();
            return;
        }// end function

        public function updateMana(event:Event = null) : void
        {
            if (this._bossInfo && this._bossInfo.type == EBossType._EBossTypeShareCollect)
            {
                if (!_entityInfo)
                {
                    return;
                }
                _shengmingBar.setValue(_entityInfo.entityInfo.mana, _entityInfo.entityInfo.maxMana);
            }
            return;
        }// end function

        override public function updateLife(event:Event = null) : void
        {
            if (this._bossInfo && this._bossInfo.type == EBossType._EBossTypeShareCollect)
            {
                return;
            }
            super.updateLife(event);
            return;
        }// end function

        override public function updateAvatar() : void
        {
            if (_entityInfo)
            {
                _avatar.bitmapData = null;
                _avatar.imgUrl = BossConfig.instance.getInfoByCode(_entityInfo.entityInfo.code).avatarId + ".png";
            }
            return;
        }// end function

        override public function updateEntity(param1:EntityInfo) : void
        {
            super.updateEntity(param1);
            this._bossInfo = BossConfig.instance.getInfoByCode(_entityInfo.entityInfo.code);
            this.updateMana();
            return;
        }// end function

        override protected function addEntityEvent() : void
        {
            super.addEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.addEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            }
            return;
        }// end function

        override protected function removeEntityEvent(event:EntityInfoEvent = null) : void
        {
            super.removeEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.removeEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            }
            return;
        }// end function

    }
}
